package com.tcs.test.str;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;

public class StrChar {

    private final Logger logger = LoggerFactory.getLogger(StrChar.class);

    @Test
    public void test() {
        String value = "你好s";
        char[] charArray = value.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            byte [] bytes = new byte[1024];
            logger.info(" char: {} , byte : {} " , charArray[i] , bytes.length);
        }
//        try {
//            byte [] byteArray = value.getBytes("UTF-8");
//            for (int i = 0; i < byteArray.length; i++) {
//                logger.info(" byte: {} " , byteArray[i]);
//            }
//        } catch (UnsupportedEncodingException e) {
//            logger.error("" , e);
//        }

        String a = "名";
        try {
            System.out.println("UTF-8编码长度:"+a.getBytes("UTF-8").length);
            System.out.println("GBK编码长度:"+a.getBytes("GBK").length);
            System.out.println("GB2312编码长度:"+a.getBytes("GB2312").length);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
